package com.top.jwtdemo.utils;


import com.sun.xml.internal.ws.developer.Serialization;
import lombok.Data;

import java.io.Serializable;

/**
 * @author  Cjj
 * @data   2024/6/17 12:51
 * @blog   统一响应类
 */
@Data
public class R<T> implements Serializable {

    //细化版本号
    @Serialization
    private static final long serialVersionUID=1L;
    //状态码
    private Integer code;
    //提示消息 成功/失败
    private String msg;
    private T data;
    private R(){
    }
    public static <T> R<T> ok(T data){
        R<T> response = new R<>();
        response.setCode(ResponseEnum.SUCCESS.getCode());
        response.setMsg(ResponseEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }

    public static <T> R<T> error(ResponseEnum responseEnum){
        R<T> response = new R<>();
        response.setCode(response.getCode());
        response.setMsg(response.getMsg());
        return response;
    }

    public static <T> R<T> error(Integer errorCode, String errorMsg){
        R<T> response = new R<>();
        response.setCode(errorCode);
        response.setMsg(errorMsg);
        return response;
    }
}
